package controllers

import (
	"doctor/models"
	beego "github.com/beego/beego/v2/server/web"
)

type DoctorController struct {
	beego.Controller
}

type JsonRes struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *DoctorController) Show() {
	ID, _ := c.GetInt("ID")
	var patient models.Patient
	err := models.DB.Model(&models.Patient{}).Where("ID=?", ID).First(&patient).Error
	if patient.Img == "" { //判断头像是否为空，要是为空的话使用默认头像
		patient.Img = "http://127.0.0.1:8080/static/img/狐狸.png"
	}
	if err != nil {
		c.Data["json"] = JsonRes{
			Code: 500,
			Msg:  "展示失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonRes{
			Code: 200,
			Msg:  "展示成功",
			Data: patient,
		}
		c.ServeJSON()
	}
}
